package com.yuanye.beans.Component;

import org.springframework.beans.factory.BeanNameAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * @author liuyandeng
 * @date 2023/7/18
 * @Description
 */

@Component
public class BeanLife implements BeanNameAware {

    @Override
    public void setBeanName(String s) {
        System.out.println("执行：BeanNameAware setBeanName 方法："+s);
    }

    // 初始化方式一：@PostConstruct
    @PostConstruct
    public void postConstruct() {
        System.out.println("执行了：@PostConstruct");
    }

    // 初始化方式二：init-method
    public void init(){
        System.out.println("执行了：init-method");
    }

    // 销毁方法一：
    @PreDestroy
    public void preDestroy(){
        System.out.println("执行了：preDestroy");
    }

    //销毁方式二：
    public void myDestroy(){
        System.out.println("执行了：myDestroy");
    }

}
